(** Bombs-Must-Detonate: Linker Lexer Generator **)
{
  open Bmdlinkparse (** Parser generator defined in bmdlinkparse.mly **)
  let line_count = ref 1
}
let digit = ['0'-'9']
let identifier = ['a'-'z' 'A'-'Z' '_']['a'-'z' 'A'-'Z' '_' '0'-'9']*

rule bmd_link = parse
  | "provide"      { PROVIDE }
  | "require"      { REQUIRE }
  | ' '            { bmd_link lexbuf }
  | '\t'           { bmd_link lexbuf }
  | '\r'           { bmd_link lexbuf }
  | '='            { EQUALS }
  | "int"          { INT }
  | "float"        { FLOAT }
  | "string"       { STRING }
  | "bool"         { BOOL }
  | "void"         { VOID }
  | "list"         { LIST }
  | "enumType"     { ENUMTYPE }
  | "enum"         { ENUM }
  | "struct"       { STRUCT }
  | "array"        { ARRAY }
  | "function"     { FUNCTION }
  | "_"            { ANYTHING }
  | "ref"          { REF }
  | "template"     { TEMPLATE }
  | ':'            { COLON }
  | ','            { COMMA }
  | '('            { LPAREN }
  | ')'            { RPAREN }
  | "->"           { ARROW }
  | '\n'           { let _ = line_count := !line_count + 1 in bmd_link lexbuf }
  | "END_HEADER"   { grab_rest lexbuf }
  | identifier as s{ IDENTIFIER s }
  | digit+ as i    { INTVAL (int_of_string i) }

and grab_rest = parse
  | _* as s        { (* reset for next parse *)line_count := 1; CODE s }
